package com.zzl.study.demo.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 从Nacos上进行MCP服务发现的客户端Controller
 *
 * @author: zhangzl
 * @date: 2025/10/20 11:43
 * @version: 1.0
 */
@RestController
@RequestMapping("/mcp/nacos")
public class NacosMcpClientController {

    private final ChatClient chatClient;

    public NacosMcpClientController(ChatClient.Builder chatClientBuilder, @Qualifier("loadbalancedMcpAsyncToolCallbacks") ToolCallbackProvider tools) {
        this.chatClient = chatClientBuilder.defaultToolCallbacks(tools).build();
    }

    /**
     * 利用MCP Router从Nacos上进行MCP服务发现的查询
     *
     * @param input 用户输入
     * @return 结果
     */
    @GetMapping("/query")
    public String query(@RequestParam("input") String input) {
        return this.chatClient.prompt(input).call().content();
    }

}
